from threading import Timer


class RepeatTimer:
    def __init__(self, interval, func, *args, **kwargs):
        self.interval = interval
        self.func = func
        self.args = args
        self.kwargs = kwargs
        self._running = False
        self._isFinish = False

    def __repeat_action(self):
        if self._isFinish: return
        self.func(*self.args, **self.kwargs)
        Timer(self.interval, self.__repeat_action).start()

    def start(self):
        if self._isFinish or self._running: return
        self._running = True
        Timer(self.interval, self.__repeat_action).start()

    def stop(self):
        if self._running and not self._isFinish:
            self._running = False
            self._isFinish = True

    def reset(self):
        if self._isFinish:
            self._isFinish = False
